﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpeedSpend : RowDataBase
{
    public int Lv, Speedspend,speed,LineNum;
}
public class SpeedSpendCfg : DataCfgBase
{
    public override string GetFilePath()
    {
        string path = DirectoryPath + "HurtSpend";
        return path;
    }
    public override RowDataBase LoadDataInfo(GameDataTableParser data)
    {
        SpeedSpend info = new SpeedSpend();
        info.id = data.GetFieldByNameAsInt("id");
        info.Lv = data.GetFieldByNameAsInt("id");
        info.Speedspend = data.GetFieldByNameAsInt("Speedmoney");
        info.speed = data.GetFieldByNameAsInt("Speed");
        info.LineNum=data.GetFieldByNameAsInt("LineNum");
        Debug.Log("LineNum" + info.LineNum);
        return info;
    }
    public IEnumerator LoadData()
    {
        return HotUpdateTools.ClientWWWLoad("Bytes/SpeedSpend.bytes", LoadClientByteCallBack);//先加载本地的配置文件

    }
    /// <summary>
    /// 加载服务器的大版本文件
    /// </summary>
    /// <param name="bundle"></param>
    private void LoadClientByteCallBack(WWW bundle)
    {

        if (bundle != null && bundle.size != 0)
        {

            Load(bundle.bytes);
            bundle.Dispose();
        }
    }
    private new void Load(byte[] byteData)
    {
        datas.Clear();

        using (GameDataTableParser gameDataTable = new GameDataTableParser()) //注意：一定要using()，这样才会自动调用这个类的Dispose()方法！！！！！！！
        {
            gameDataTable.ReadTableFromBytes(byteData, true);

            gameDataTable.first();
            while (!gameDataTable.eof())
            {
                RowDataBase info = LoadDataInfo(gameDataTable);
                datas.Add(info.id, info);
                gameDataTable.next();
            }
        }
        DatasSort();
    }

    public SpeedSpend GetData(int id)
    {
        Debug.Log(datas.Count);
        foreach (int key in datas.Keys)
        {
            if (key == id)
                return datas[key] as SpeedSpend;
        }
        return null;
    }


    public List<SpeedSpend> lisAllData = new List<SpeedSpend>();

    private void DatasSort()
    {
        foreach (int key in datas.Keys)
        {
            lisAllData.Add(datas[key] as SpeedSpend);
            //return datas[key] as PackagingCfgRowData;
        }

        //根据time进行快速排序存入List中
        //sort(lisAllData, 0, lisAllData.Count - 1);
    }





}
